package org.hit.burkun.umls;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import org.hit.burkun.db.DBHelper;
import org.hit.burkun.entities.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//将Mesh映射到Umls中
public class MeshUmlsMapper extends BaseMapper{
	//http://www.nlm.nih.gov/research/umls/sourcereleasedocs/current/MSH/index.html
	private MapidsUmlsDump mapDbh;
	private Entity.TYPE type = Entity.TYPE.MSH;

	private static Logger logger = LoggerFactory.getLogger(MeshUmlsMapper.class);

	public MeshUmlsMapper(DBHelper dbh, String tbName, MapidsUmlsDump mapDbh) {
		super(dbh, tbName);
		this.mapDbh = mapDbh;
	}

	public MeshUmlsMapper(DBHelper dbh, MapidsUmlsDump mapDbh) {
		this(dbh, "MRCONSO" ,mapDbh);
	}
	
	@Override
	public void process(Map<String, Set<String>> data) {
		mapDbh.saveMappedToDb(type, data);
	}
	
	public void quickMap() {
		//"SELECT distinct CUI, CODE FROM umls.MRCONSO where SAB = 'MSH'";
		logger.debug("get cui and meshid from umls db...");
		Collection<String[]> res = dbh.queryData("SELECT distinct CUI, CODE FROM MRCONSO where SAB = 'MSH'", 2);
		Map<String, Set<String>> mapData = getMapedData(res);
		process(mapData);
	}
	

	public static void main(String[] args) {
//		DBHelper dbh = DBHelper.getUMLSDBHelper();
//		MapidsUmlsDump mapDbh = new MapidsUmlsDump(
//				getServerBioSearch(), "map_umls_ids");
//		MeshUmlsMapper mapper = new MeshUmlsMapper(dbh, mapDbh);
//		mapper.begin();
//		mapper.quickMap();
//		mapper.end();
	}
	
	
}
